<?php
namespace Common\Model;

/**
 * 钟点房价格
 * @modify zhangzhen 2017-5-15 创建
 * @index 无
 */

Class HourPriceModel extends \Common\Model\BaseModel
{
    protected $trueTableName = 'tb_hour_price';

    protected function _before_insert(&$data, $options) {
    }
    protected function _before_update(&$data, $options) {
    }
    /**
     * 批量添加钟点房价格
     * @modify zhangzhen 2017-5-15 创建
     * @param  array   $dataList = [
                            'hotel',
                            'price',
                            'hour',
                            'roomTypeId',
                        ];
     * @return boolean 执行结果
     */
    public function getInfoByRoomType($roomTypeId) {
        $result = $this->where(['roomtype_id' => $roomTypeId])->field('hour,price')->select();
        return $result;
    }

    public function getInfosByHotel($hotelId) {
        $result = $this->where(['hotelentity_id' => $hotelId])->field('roomtype_id,hour,price')->select();
        return $result;
    }

    public function getPriceByRoomTypeAndHour($roomTypeId, $hour) {
        $result = $this->where(['roomtype_id' => $roomTypeId, 'hour' => $hour])->field('hour,price')->find();
        return $result;
    }

    /**
     * 批量添加钟点房价格
     * @modify zhangzhen 2017-5-15 创建
     * @param  array   $dataList = [
                            'hotel',
                            'price',
                            'hour',
                            'roomTypeId',
                        ];
     * @return boolean 执行结果
     */
    public function addAllInfos(array $dataList) {
        $result = $this->addAll($dataList);
        return $result;
    }
    
    /**
     * 修改钟点房价格
     * @modify zhangzhen 2017-5-15 创建
     * @param  int   $roomTypeId
     * @param  int   $hour
     * @param  string   $price
     * @return boolean 执行结果
     */
    public function saveInfoByRoomTypeAndHour($roomTypeId,$hour,$price) {
        $option = [
            'roomtype_id' => $roomTypeId,
            'hour' => $hour,
        ];
        $data['price'] = $price;
        $result = $this->where($option)->save($data);
        return $result === false ? false : true;
    }

    /**
     * 查找钟点房价格
     * @modify zhangzhen 2017-8-18 创建
     * @param  int   $roomTypeId
     * @return boolean 执行结果
     */
    public function getPriceByRoomType($roomTypeId) {
        $option = [
            'roomtype_id' => $roomTypeId,
        ];
        $result = $this->where($option)->select();
        return $result;
    }

    /**
     * 根据房型删除钟点房价格
     * @modify zhangzhen 2017-5-16 创建
     * @param  string   $roomTypeId 房型id
     * @return boolean 执行结果
     */
    public function deleteInfoByTypeId($roomTypeId) {
        $option['roomtype_id'] = $roomTypeId;
        $result = $this->where($option)->delete();
        return $result === false ? false : true;
    }
}
